package org.dangran.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class SystemLogAspect {

    @Pointcut("@annotation(org.dangran.aop.SystemLog)")
    public void logAspect(){
    }


    @Before("logAspect()")
    public Object doBefore(JoinPoint joinPoint){
        System.out.println("Before");
        return "Before";
    }

    @Around("logAspect()")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("Around---方法执行前");
        Object proceed = joinPoint.proceed();
        System.out.println("Around---方法执行后");
        return proceed;
    }

    @AfterThrowing(pointcut = "logAspect()",throwing = "e")
    public void doAfterThrowing(JoinPoint joinPoint,Exception e){
        System.out.println("doAfterThrowing");
    }

    @After("logAspect()")
    public void doAfter(JoinPoint joinPoint){
        Object[] args = joinPoint.getArgs();
        System.out.println("After");
    }


}
